namespace PDUConverter.SmartMessaging
{
    /// <summary>
    /// Implements a Concatenated Short Message Information Element (8-bit reference number)
    /// </summary>
    /// <remarks>This element is used to indiate that a message is split into
    /// multiple parts.</remarks>
    public class ConcatMessageElement : InformationElement
    {
        private byte currentNumber;
        private byte referenceNumber;
        private byte totalMessages;

        /// <summary>
        /// Initializes a new instance of the <see cref="T:GsmComm.PduConverter.SmartMessaging.ConcatMessageElement" /> class.
        /// </summary>
        /// <param name="referenceNumber">The message's reference number, must
        /// be the same in all parts of the same message.</param>
        /// <param name="totalMessages">The total number of parts of the message.</param>
        /// <param name="currentNumber">The current message number.</param>
        public ConcatMessageElement(byte referenceNumber, byte totalMessages, byte currentNumber) : base(0)
        {
            this.referenceNumber = referenceNumber;
            this.totalMessages = totalMessages;
            this.currentNumber = currentNumber;
        }

        /// <summary>
        /// Returns the byte array equivalent of this instance.
        /// </summary>
        /// <returns>The byte array.</returns>
        public override byte[] ToByteArray()
        {
            return new byte[] { base.Identifier, 3, this.referenceNumber, this.totalMessages, this.currentNumber };
        }

        /// <summary>
        /// Gets the current message number.
        /// </summary>
        public byte CurrentNumber
        {
            get
            {
                return this.currentNumber;
            }
        }

        /// <summary>
        /// Gets the messages reference number.
        /// </summary>
        public byte ReferenceNumber
        {
            get
            {
                return this.referenceNumber;
            }
        }

        /// <summary>
        /// Gets the total number of parts of the message.
        /// </summary>
        public byte TotalMessages
        {
            get
            {
                return this.totalMessages;
            }
        }
    }
}